<?php

namespace app\admin\model\note;

use think\Model;


class Okr extends Model
{

    

    

    // 表名
    protected $name = 'note_okr';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [];

	/**
	 * 批量修改一周okr
	 * @param array $okrs
	 * @param int $week_id
	 * @param $uid
	 * @param $customer_id
	 * @param $contact_id
	 * @return true
	 * @throws \Exception
	 */
	public function editWeek(array $okrs, int $week_id, $uid, $customer_id, $contact_id){
		array_walk($okrs, function (&$value) use ($week_id, $uid, $customer_id, $contact_id) {
			if(!$value['id']){
				unset($value['id']);
				$value['week_id'] = $week_id;
				$value['uid'] = $uid;
				$value['customer_id'] = $customer_id;
				$value['contact_id'] = $contact_id;
				$value['create_time'] = time();
				$value['update_time'] = time();
			}
		});
		$this->saveAll($okrs);
		return true;
	}
}
